package com.shopping.controller;

import com.shopping.bean.User;
import com.shopping.util.SYS;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("page")
public class PageController {



    @RequestMapping("index")
    public String index(){
            return "shopping/index.html";
    }
    @RequestMapping("login")
    public String login() {
        return "shopping/login.html";
    }
        @RequestMapping("cart")
        public String cart(){
            return "shopping/cart.html";
    }

    //订单的跳转
    @RequestMapping("order")
    public String order(String productids,String counts,Model model){
            model.addAttribute("productids",productids);
            model.addAttribute("counts",counts);
            return "shopping/order.html";
    }

    @RequestMapping("orderConfirm")
    public String orderConfirm(String productids,String counts,Model model){
        model.addAttribute("productids",productids);
        model.addAttribute("counts",counts);
        return "shopping/orderConfirm.html";
    }

    @RequestMapping("detail")
    public String detail(Integer id, Model model){
            model.addAttribute("id",id);
            return "shopping/detail.html";
    }
    @RequestMapping("list")
    public String list(){
        return "shopping/list.html";
    }

    @RequestMapping("profile")
    public String profile(HttpSession session,Model model){
        User loggedInUser=(User)session.getAttribute(SYS.SHOPPING_LOGIN_USER);
        if (loggedInUser == null) {
            // 用户未登录，重定向到登录页面
            return "redirect:/page/login";
        }
        return "shopping/profile.html";
    }

    @RequestMapping("adress")
    public String adress(){
        return "shopping/adress.html";
    }
    @RequestMapping("register")
    public String register(){
            return "shopping/register";
    }


}
